HAL CORTEX MPU functions migration

Note

The MPU migration functions are divided according to their ARM Architecture. Each Architecture contains multiple CORTEX versions that are used in your STM32 series.

For example:

  • ARMv8-M: CORTEX-M33 (STM32U5…)

  • ARMv7-M: CORTEX-M7, CORTEX-M4 (STM32H7, STM32L4…)

  • ARMv6-M: CORTEX-M0, CORTEX-M0+ (STM32F0, STM32U0…)

You can find your Series in ST website: Link ( https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html)

HAL_MPU_Enable

HAL1

HAL2

The function HAL_MPU_Enable is responsible for enabling the Memory Protection Unit (MPU) with a specified control setting:

This function has been updated and renamed to HAL_CORTEX_MPU_Enable:

Functionality Update:

  • Use specific enumerations hal_cortex_mpu_hardfault_nmi_state_t and hal_cortex_mpu_unmapped_addr_fault_t for fault handling and default memory map settings, enhancing type safety and clarity.

void HAL_MPU_Enable(uint32_t MPU_Control)
void HAL_CORTEX_MPU_Enable(hal_cortex_mpu_hardfault_nmi_state_t fault_state,
                           hal_cortex_mpu_unmapped_addr_fault_t priv_default_state)

HAL_MPU_Disable

HAL1

HAL2

The function HAL_MPU_Disable was responsible for disabling the MPU (Memory Protection Unit):

This function has been renamed to HAL_CORTEX_MPU_Disable:

void HAL_MPU_Disable(void)
void HAL_CORTEX_MPU_Disable(void)

HAL_MPU_EnableRegion

HAL1

HAL2

The function HAL_MPU_EnableRegion is responsible for enabling a specific region in the Memory Protection Unit (MPU):

This function has been updated and renamed to HAL_CORTEX_MPU_EnableRegion:

Functionality Update:

  • Use specific enumeration hal_cortex_mpu_region_idx_t for the region index, enhancing type safety and clarity.

void HAL_MPU_EnableRegion(uint32_t RegionNumber)
void HAL_CORTEX_MPU_EnableRegion(hal_cortex_mpu_region_idx_t region_idx)

HAL_MPU_DisableRegion

HAL1

HAL2

The function HAL_MPU_DisableRegion is responsible for disabling a specific region in the Memory Protection Unit (MPU):

This function has been updated and renamed to HAL_CORTEX_MPU_DisableRegion:

Functionality Update:

  • Use specific enumeration hal_cortex_mpu_region_idx_t for the region index, enhancing type safety and clarity.

void HAL_MPU_DisableRegion(uint32_t RegionNumber)
void HAL_CORTEX_MPU_DisableRegion(hal_cortex_mpu_region_idx_t region_idx)

HAL_MPU_ConfigRegion

HAL1

HAL2

The function HAL_MPU_ConfigRegion is responsible for configuring a specific region in the Memory Protection Unit (MPU):

This function has been updated and renamed to HAL_CORTEX_MPU_SetConfigRegion:

Functionality Update:

  • Use specific enumeration hal_cortex_mpu_region_idx_t for the region index and hal_cortex_mpu_region_config_t for the configuration parameters, enhancing type safety and clarity.

  • Return a status indicating success or failure of the configuration.

void HAL_MPU_ConfigRegion(const MPU_Region_InitTypeDef
                          *const pMPU_RegionInit)
hal_status_t HAL_CORTEX_MPU_SetConfigRegion(hal_cortex_mpu_region_idx_t region_idx,
                                            const hal_cortex_mpu_region_config_t *p_config)
Related use cases:

HAL_MPU_ConfigMemoryAttributes

HAL1

HAL2

The function HAL_MPU_ConfigMemoryAttributes is responsible for configuring memory attributes for the Memory Protection Unit (MPU):

Functionality:

  • Configure memory attributes for the MPU.

  • Ensure the memory attributes configuration parameters are valid.

This function has been divided into two separate functions: HAL_CORTEX_MPU_SetDeviceMemAttr and HAL_CORTEX_MPU_SetCacheMemAttr:

Functionality Split:

  1. `HAL_CORTEX_MPU_SetDeviceMemAttr`

    • Configure device memory attributes for the MPU.

    • Ensure the memory attribute index and device memory attributes are valid.

    • Use specific enumeration hal_cortex_mpu_mem_attr_idx_t for the memory attribute index and hal_cortex_mpu_device_mem_attr_t for the device memory attributes, enhancing type safety and clarity.

  2. `HAL_CORTEX_MPU_SetCacheMemAttr`

    • Configure cacheable memory attributes for the MPU.

    • Ensure the memory attribute index and cacheable memory attributes are valid.

    • Use specific enumeration hal_cortex_mpu_mem_attr_idx_t for the memory attribute index and hal_cortex_mpu_normal_mem_cache_attr_t for the cacheable memory attributes, enhancing type safety and clarity.

void HAL_MPU_ConfigMemoryAttributes(const MPU_Attributes_InitTypeDef
                                    *const pMPU_AttributesInit)
void HAL_CORTEX_MPU_SetDeviceMemAttr(hal_cortex_mpu_mem_attr_idx_t attr_idx,
                                     hal_cortex_mpu_device_mem_attr_t mem_attr)
void HAL_CORTEX_MPU_SetCacheMemAttr(hal_cortex_mpu_mem_attr_idx_t attr_idx,
                                     hal_cortex_mpu_normal_mem_cache_attr_t mem_attr)
Related use cases:

Note

The MPU Not Secure functions are only available with ARMv8-M Architecture or above.

HAL_MPU_Enable_NS

HAL1

HAL2

The function HAL_MPU_Enable_NS was responsible for enabling the non-secure MPU (Memory Protection Unit):

This function has been renamed to HAL_CORTEX_MPUNS_Enable:

void HAL_MPU_Enable_NS(void)
void HAL_CORTEX_MPUNS_Enable(void)

HAL_MPU_Disable_NS

HAL1

HAL2

The function HAL_MPU_Disable_NS was responsible for disabling the non-secure MPU (Memory Protection Unit):

This function has been renamed to HAL_CORTEX_MPUNS_Disable:

void HAL_MPU_Disable_NS(void)
void HAL_CORTEX_MPUNS_Disable(void)

HAL_MPU_EnableRegion_NS

HAL1

HAL2

The function HAL_MPU_EnableRegion_NS was responsible for enabling a region in the non-secure MPU (Memory Protection Unit):

This function has been renamed to HAL_CORTEX_MPUNS_EnableRegion:

void HAL_MPU_EnableRegion_NS(void)
void HAL_CORTEX_MPUNS_EnableRegion(void)

HAL_MPU_DisableRegion_NS

HAL1

HAL2

The function HAL_MPU_DisableRegion_NS was responsible for disabling a region in the non-secure MPU (Memory Protection Unit):

This function has been renamed to HAL_CORTEX_MPUNS_DisableRegion:

void HAL_MPU_DisableRegion_NS(void)
void HAL_CORTEX_MPUNS_DisableRegion(void)

HAL_MPU_ConfigRegion_NS

HAL1

HAL2

The function HAL_MPU_ConfigRegion_NS was responsible for configuring a region in the non-secure MPU (Memory Protection Unit):

This function has been renamed to HAL_CORTEX_MPUNS_SetConfigRegion:

void HAL_MPU_ConfigRegion_NS(void)
void HAL_CORTEX_MPUNS_SetConfigRegion(void)

HAL_MPU_ConfigMemoryAttributes_NS

HAL1

HAL2

The function HAL_MPU_ConfigMemoryAttributes_NS was responsible for configuring memory attributes in the non-secure MPU (Memory Protection Unit):

This function has been split into HAL_CORTEX_MPUNS_SetDeviceMemAttr and HAL_CORTEX_MPUNS_SetCacheMemAttr:

void HAL_MPU_ConfigMemoryAttributes_NS(void)
void HAL_CORTEX_MPUNS_SetDeviceMemAttr(void)
void HAL_CORTEX_MPUNS_SetCacheMemAttr(void)